package com.examine.serviceImpl;

import com.examine.bean.AccessApplication;
import com.examine.bean.User;
import com.examine.dao.AccessApplicationMapper;
import com.examine.dao.UserMapper;
import com.examine.service.AccessApplicationService;
import com.examine.utils.DataConfig;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AccessApplicationServiceImpl implements AccessApplicationService {
    private static SqlSession session = null;
    private static AccessApplicationMapper applicationMapper = null;
    private AccessApplication application = null;
    private List<AccessApplication> applicationList = null;
    private int count = 0;

    public static void dataConfig(){
        try{
            session = DataConfig.getSession();
            applicationMapper = session.getMapper(AccessApplicationMapper.class);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
    @Override
    public int deleteByPrimaryKey(String id) {
        dataConfig();

        try{
            count = applicationMapper.deleteByPrimaryKey(id);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }


    @Override
    public int insertSelective(AccessApplication record) {
        dataConfig();

        try{
            count = applicationMapper.insertSelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public AccessApplication selectByPrimaryKey(String id) {
        dataConfig();

        try{
            application = applicationMapper.selectByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return application;
    }

    @Override
    public int updateByPrimaryKeySelective(AccessApplication record) {
        dataConfig();

        try{
            count = applicationMapper.updateByPrimaryKeySelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public List<AccessApplication> shareQueryApplication(AccessApplication record) {
        dataConfig();

        try{
            applicationList = applicationMapper.shareQueryApplication(record);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }

        return applicationList;
    }

    @Override
    public int queryAccessCountLike(AccessApplication record) {
        dataConfig();

        try{
            count = applicationMapper.queryAccessCountLike(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

}
